/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.date.DateUtil
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.ActionEvent
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.Button
 *  javafx.scene.control.ComboBox
 *  javafx.scene.control.DatePicker
 *  javafx.scene.control.Label
 *  javafx.scene.control.ScrollPane
 *  javafx.scene.control.TableColumn
 *  javafx.scene.control.TableView
 *  javafx.scene.control.cell.PropertyValueFactory
 *  javafx.scene.layout.VBox
 *  javafx.util.Callback
 *  javafx.util.StringConverter
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.gys.controller.member;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.MemberCardReportUtil;
import com.gys.common.business.SaleScheduleSettingUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.data.KeyValue;
import com.gys.common.util.CacheUtil;
import com.gys.common.util.CommonUtil;
import com.gys.common.util.ExcelUtil;
import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.data.example.GetLoginStoreOutData;
import com.gys.data.example.GetUserOutData;
import com.gys.data.member.GetMemberCardReportInData;
import com.gys.data.member.GetMemberCardReportOutData;
import com.gys.data.saleScheduleSetting.GetSaleScheduleInData;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import javafx.util.StringConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@FXMLController
public class MemberCardReportController
extends BaseController
implements Initializable {
    private static final Logger log = LoggerFactory.getLogger(MemberCardReportController.class);
    @FXML
    private TableColumn<GetMemberCardReportOutData, String> bc;
    @FXML
    private DatePicker queryStartDate;
    @FXML
    private ComboBox<String> querySyNum;
    @FXML
    private ScrollPane scrollPane;
    @FXML
    private ComboBox<KeyValue> queryBc;
    @FXML
    private TableColumn<GetMemberCardReportOutData, String> brId;
    @FXML
    private TableColumn<GetMemberCardReportOutData, String> index;
    @FXML
    private TableView<GetMemberCardReportOutData> tableData;
    @FXML
    private TableColumn<GetMemberCardReportOutData, String> syNum;
    @FXML
    private Button sureBtn;
    @FXML
    private TableColumn<GetMemberCardReportOutData, String> addNum;
    @FXML
    private DatePicker queryEndDate;
    @FXML
    private Label querySyNumLabel;
    @FXML
    private Label queryBcLabel;
    @FXML
    private Label queryStartDateLabel;
    @FXML
    private Label queryEndDateLabel;
    @FXML
    private VBox vbox;
    @FXML
    private TableColumn<GetMemberCardReportOutData, String> brName;
    private ObservableList<GetMemberCardReportOutData> observableTableList = FXCollections.observableArrayList(new ArrayList());

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.scrollPane.setPrefWidth(this.getContentWidth());
        this.scrollPane.setPrefHeight(this.getContentHeight());
        this.vbox.setPrefHeight(this.getContentHeight());
        this.vbox.setPrefWidth(this.getContentWidth());
        this.tableData.setPrefWidth(this.getContentWidth() * 0.9);
        this.tableData.setPrefHeight(this.getContentHeight() * 0.65);
        StringConverter converter = CommonUtil.dataPickerFormat("yyyyMMdd");
        this.queryStartDate.setConverter(converter);
        this.queryEndDate.setConverter(converter);
        CommonUtil.comboxInit(this.queryBc);
    }

    @Override
    public void init() {
        ArrayList<String> names;
        this.querySyNum.setValue("");
        List outDataList = null;
        GetSaleScheduleInData inData = new GetSaleScheduleInData();
        inData.setClientId(((GetUserOutData)CacheUtil.get("logInUser")).getClient());
        inData.setGsegBrId(((GetLoginStoreOutData)CacheUtil.get("store")).getStoCode());
        HttpJson httpJson = SaleScheduleSettingUtil.queryUser(CommonUtil.convertToMap(inData));
        if (httpJson.isSuccess()) {
            outDataList = JSON.parseArray((String)httpJson.getMsg(), GetUserOutData.class);
            names = new ArrayList<String>();
            if (ObjectUtil.isNotEmpty(outDataList)) {
                for (int i = 0; i < outDataList.size(); ++i) {
                    GetUserOutData userOutData = (GetUserOutData)outDataList.get(i);
                    names.add(userOutData.getUserId());
                }
            }
        } else {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return;
        }
        this.querySyNum.setItems(FXCollections.observableArrayList(names));
        this.queryBc.setValue(new KeyValue());
        this.queryBc.setItems(FXCollections.observableArrayList(Arrays.asList(new KeyValue("\u65e9\u73ed", "1"), new KeyValue("\u4e2d\u73ed", "2"), new KeyValue("\u665a\u73ed", "3"), new KeyValue("\u901a\u73ed", "0"))));
        this.initTableView();
    }

    private TableView<GetMemberCardReportOutData> initTableView() {
        GetMemberCardReportInData inData = new GetMemberCardReportInData();
        inData.setClientId(((GetUserOutData)CacheUtil.get("logInUser")).getClient());
        inData.setQuerySyNum((String)this.querySyNum.getValue());
        inData.setQueryBc(((KeyValue)this.queryBc.getValue()).getValue());
        if (ObjectUtil.isNotEmpty(this.queryStartDate.getValue())) {
            inData.setQueryStartDate(DateUtil.format((Date)DateUtil.parse((String)((LocalDate)this.queryStartDate.getValue()).toString()), (String)"yyyy-MM-dd HH:mm:ss"));
        }
        if (ObjectUtil.isNotEmpty(this.queryEndDate.getValue())) {
            inData.setQueryEndDate(DateUtil.format((Date)DateUtil.endOfDay((Date)DateUtil.parse((String)((LocalDate)this.queryEndDate.getValue()).toString())), (String)"yyyy-MM-dd HH:mm:ss"));
        }
        if (ObjectUtil.isNotEmpty(this.queryStartDate.getValue()) && ObjectUtil.isNotEmpty(this.queryEndDate.getValue()) && String.valueOf(this.queryStartDate.getValue()).compareTo(String.valueOf(this.queryEndDate.getValue())) > 0) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u5f00\u59cb\u65e5\u671f\u4e0d\u80fd\u5927\u4e8e\u7ed3\u675f\u65e5\u671f");
            alert.showAndWait();
            return new TableView();
        }
        List dataList = null;
        HttpJson httpJson = MemberCardReportUtil.queryReport(CommonUtil.convertToMap(inData));
        if (httpJson.isSuccess()) {
            dataList = JSON.parseArray((String)httpJson.getMsg(), GetMemberCardReportOutData.class);
        } else {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
        }
        this.observableTableList.clear();
        if (ObjectUtil.isNotEmpty(dataList)) {
            this.observableTableList = FXCollections.observableArrayList((Collection)dataList);
        }
        this.bingTableCell();
        this.tableData.setItems(this.observableTableList);
        return this.tableData;
    }

    private void bingTableCell() {
        this.bc.setCellValueFactory((Callback)new PropertyValueFactory(this.bc.getId()));
        this.brId.setCellValueFactory((Callback)new PropertyValueFactory(this.brId.getId()));
        this.index.setCellValueFactory((Callback)new PropertyValueFactory(this.index.getId()));
        this.syNum.setCellValueFactory((Callback)new PropertyValueFactory(this.syNum.getId()));
        this.addNum.setCellValueFactory((Callback)new PropertyValueFactory(this.addNum.getId()));
        this.brName.setCellValueFactory((Callback)new PropertyValueFactory(this.brName.getId()));
    }

    @FXML
    void sureBtnAction(ActionEvent event) {
        String bc = ((KeyValue)this.queryBc.getValue()).getValue();
        String syNum = (String)this.querySyNum.getValue();
        LocalDate startDate = (LocalDate)this.queryStartDate.getValue();
        LocalDate endDate = (LocalDate)this.queryEndDate.getValue();
        if (ObjectUtil.isEmpty(bc) && ObjectUtil.isEmpty(syNum) && ObjectUtil.isEmpty(startDate) && ObjectUtil.isEmpty(endDate)) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u81f3\u5c11\u586b\u5199\u4e00\u9879\u5185\u5bb9\u8fdb\u884c\u67e5\u8be2");
            alert.showAndWait();
            return;
        }
        this.initTableView();
    }

    @FXML
    void exportBtnAction(ActionEvent event) {
        GetMemberCardReportInData inData = new GetMemberCardReportInData();
        inData.setClientId(((GetUserOutData)CacheUtil.get("logInUser")).getClient());
        inData.setQuerySyNum((String)this.querySyNum.getValue());
        inData.setQueryBc(((KeyValue)this.queryBc.getValue()).getValue());
        if (ObjectUtil.isNotEmpty(this.queryStartDate.getValue())) {
            inData.setQueryStartDate(DateUtil.format((Date)DateUtil.parse((String)((LocalDate)this.queryStartDate.getValue()).toString()), (String)"yyyy-MM-dd HH:mm:ss"));
        }
        if (ObjectUtil.isNotEmpty(this.queryEndDate.getValue())) {
            inData.setQueryEndDate(DateUtil.format((Date)DateUtil.endOfDay((Date)DateUtil.parse((String)((LocalDate)this.queryEndDate.getValue()).toString())), (String)"yyyy-MM-dd HH:mm:ss"));
        }
        HttpJson httpJson = MemberCardReportUtil.queryReport(CommonUtil.convertToMap(inData));
        List dataList = null;
        if (httpJson.isSuccess()) {
            dataList = JSON.parseArray((String)httpJson.getMsg(), GetMemberCardReportOutData.class);
        } else {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
        }
        List<String> columnName = Arrays.asList("\u5e8f\u53f7", "\u5e97\u53f7", "\u5e97\u540d", "\u6536\u94f6\u5de5\u53f7", "\u73ed\u6b21", "\u65b0\u589e\u4f1a\u5458\u6570\u91cf");
        List<String> columnId = Arrays.asList("index", "brId", "brName", "syNum", "bc", "addNum");
        boolean result = ExcelUtil.export("\u4f1a\u5458\u5361\u65b0\u589e\u6570\uff08\u7ebf\u4e0b\uff09\u67e5\u8be2\u62a5\u8868", dataList, columnName, columnId);
        if (result) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u5bfc\u51fa\u6210\u529f");
            alert.showAndWait();
        }
    }

    @FXML
    private void restQuery(ActionEvent event) {
        this.querySyNum.setValue("");
        this.queryStartDate.setValue(null);
        this.queryBc.setValue(new KeyValue());
        this.queryEndDate.setValue(null);
    }
}

